﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CodeAuto.DALS
{
    public class TableDALS
    {

        public static string GetModelString(Models.T_Project project, Models.T_Table table, List<Models.T_Field> fields)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("using System;<br/>");
            sb.AppendLine("using System.Collections.Generic;<br/>");
            sb.AppendLine("namespace " + project.ProjectName + ".Models<br/>");
            sb.AppendLine("{<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\"&gt;");
            sb.AppendLine("    /// &lt;summary&gt;<br/>");
            sb.AppendLine("    /// " + table.Description + "<br/>");
            sb.AppendLine("    /// &lt;/summary&gt;<br/>");
            sb.AppendLine("    <span style=\"color:blue;\">public class</span> " + table.TableName + "<br/>");
            sb.AppendLine("    {<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            for (int i = 0; i < fields.Count; i++)
            {
                sb.AppendLine("        /// &lt;summary&gt;<br/>");
                sb.AppendLine("        /// " + fields[i].FieldName + "<br/>");
                sb.AppendLine("        /// &lt;/summary&gt;<br/>");
                sb.AppendLine("        <span style=\"color:blue;\">public</span> " + fields[i].Attr + "  " + fields[i].Field + " { get; set; }<br/>");
                sb.AppendLine("<br/>");

                if (fields[i].Field.EndsWith("Id") && fields[i].Field.Length > 2)
                {
                    sb.AppendLine("        /// &lt;summary&gt;<br/>");
                    sb.AppendLine("        /// 相关" + fields[i].FieldName.Replace("编号", "") + "<br/>");
                    sb.AppendLine("        /// &lt;/summary&gt;<br/>");
                    sb.AppendLine("        <span style=\"color:blue;\">public</span> virtual " + fields[i].Field.Replace("Id", "") + "  " + fields[i].Field.Replace("Id", "") + " { get; set; }<br/>");
                    sb.AppendLine("<br/>");
                }
                sb.AppendLine("<br/>");
            }
            sb.AppendLine("public " + table.TableName + "(){" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Attr.Equals("int"))
                {
                    sb.AppendLine("this." + fields[i].Field + "=int.MinValue;<br/>");
                }
            }
            sb.AppendLine("</div>");
            sb.AppendLine("}" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/>");
            sb.AppendLine("</div>");

            sb.AppendLine("}<br/>");
            return sb.ToString();
        }


        public static string GetInterfaceString(Models.T_Project project, Models.T_Table table)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("using System;<br/>");
            sb.AppendLine("using System.Collections.Generic;<br/>");
            sb.AppendLine("using " + project.ProjectName + ".Models;<br/>");
            sb.AppendLine("namespace " + project.ProjectName + ".Interfaces<br/>");
            sb.AppendLine("{<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("public interface I" + table.TableName + "<br/>");
            sb.AppendLine("{<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");

            sb.AppendLine("#region 默认接口<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;<br/>");
            sb.AppendLine("        /// 得到所有 " + table.Description + "在大项目中尽量少用，这个方法返回的数据量过于庞大<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;所有" + table.Description + "&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        List&lt;" + table.TableName + "&gt; GetList();<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 分页显示" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageSize\"&gt;每页记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"NowPage\"&gt;当前页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageCount\"&gt;总共多少页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"recordCount\"&gt;总记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;查询到的记录&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        List&lt;" + table.TableName + "&gt; GetListByPage(int PageSize, int NowPage, out int PageCount, out int recordCount);<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 分页模糊查询" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageSize\"&gt;每页记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"NowPage\"&gt;当前页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageCount\"&gt;总共多少页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"recordCount\"&gt;总记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;查询到的记录&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        List&lt;" + table.TableName + "&gt; GetListByPageLikeKey(" + table.TableName + " " + table.TableName.ToLower() + ",int PageSize, int NowPage, out int PageCount, out int recordCount);<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 分页查询" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageSize\"&gt;每页记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"NowPage\"&gt;当前页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageCount\"&gt;总共多少页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"recordCount\"&gt;总记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;查询到的记录&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        List&lt;" + table.TableName + "&gt; GetListByPageAndKeys(" + table.TableName + " " + table.TableName.ToLower() + ",int PageSize, int NowPage, out int PageCount, out int recordCount);<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 得到一个" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"id\"&gt;编号&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;对象&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        " + table.TableName + " GetModel(int id);<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 保存一个" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;编号&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        int Insert(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 按关键字查询头几条" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"count\"&gt;数量&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;" + table.Description + "的列表&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        List&lt;" + table.TableName + "&gt; GetTopList(int count);<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 判断" + table.Description + "是否唯一存在" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;是否存在&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        bool IsExist(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 判断" + table.Description + "是否存在" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;是否存在&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        bool IsJustExist(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 得到关键字等于。。。的所有" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;" + table.Description + "的List&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        List&lt;" + table.TableName + "&gt; GetSomeObject(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 编辑一个" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        void Edit(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 删除一个" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        void Delete(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 删除所有" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        void DeleteAll();<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 按关键字删除" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        void DeleteColumByKey_Value(" + table.TableName + " " + table.TableName.ToLower() + ");<br/><br/>");

            sb.AppendLine("#endregion<br/><br/>");

            sb.AppendLine("#region 自定义接口<br/><br/><br/>");


            sb.AppendLine("#endregion<br/><br/>");

            sb.AppendLine("</div>");
            sb.AppendLine("}");

            sb.AppendLine("</div>");
            sb.AppendLine("}");

            return sb.ToString();
        }


        public static string GetImplString(Models.T_Project project, Models.T_Table table)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("using System;<br/>");
            sb.AppendLine("using System.Collections.Generic;<br/>");
            sb.AppendLine("using " + project.ProjectName + ".Models;<br/>");
            sb.AppendLine("using " + project.ProjectName + ".Interfaces;<br/>");
            sb.AppendLine("namespace " + project.ProjectName + ".Impls<br/>");
            sb.AppendLine("{<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("public class Impl" + table.TableName + ":I" + table.TableName + "<br/>");
            sb.AppendLine("{<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("private DavidDB.ADO.DBManager dbmanager=null;<br/>");
            sb.AppendLine("<br/>");
            sb.AppendLine("<br/>");
            sb.AppendLine("#region 返回接口实现<br/><br/>");
            sb.AppendLine("private Impl" + table.TableName + "(DavidDB.ADO.DBManager db){this.dbmanager=db;}<br/><br/>");
            sb.AppendLine("public static I" + table.TableName + " GetInstance(DavidDB.ADO.DBManager db){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("I" + table.TableName + " instance=new Impl" + table.TableName + "(db);<br/>");
            sb.AppendLine("return instance;<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/>");

            sb.AppendLine("#endregion<br/>");


            sb.AppendLine("#region 默认接口实现<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;<br/>");
            sb.AppendLine("        /// 得到所有 " + table.Description + "在大项目中尽量少用，这个方法返回的数据量过于庞大<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;所有" + table.Description + "&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public List&lt;" + table.TableName + "&gt; GetList(){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            " + table.TableName + " field = new " + table.TableName + "();" + "<br/>");
            sb.AppendLine("            var objs = dbmanager.GetList(field);" + "<br/>");
            sb.AppendLine("            List&lt;" + table.TableName + "&gt; fields = new List&lt;" + table.TableName + "&gt;();" + "<br/>");
            sb.AppendLine("            foreach (" + table.TableName + " _field in objs)" + "<br/>");
            sb.AppendLine("            {" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("                fields.Add(_field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("            }" + "<br/>");
            sb.AppendLine("            return fields;" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 分页显示" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageSize\"&gt;每页记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"NowPage\"&gt;当前页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageCount\"&gt;总共多少页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"recordCount\"&gt;总记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;查询到的记录&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public List&lt;" + table.TableName + "&gt; GetListByPage(int PageSize, int NowPage, out int PageCount, out int recordCount){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            " + table.TableName + " field = new " + table.TableName + "();" + "<br/>");
            sb.AppendLine("            var objs = dbmanager.GetListByPage(PageSize, NowPage, out PageCount, out recordCount, field);" + "<br/>");
            sb.AppendLine("            List&lt;" + table.TableName + "&gt; fields = new List&lt;" + table.TableName + "&gt;();" + "<br/>");
            sb.AppendLine("            foreach (" + table.TableName + " _field in objs)" + "<br/>");
            sb.AppendLine("            {" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("                fields.Add(_field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("            }" + "<br/>");
            sb.AppendLine("            return fields;" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 分页模糊查询" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageSize\"&gt;每页记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"NowPage\"&gt;当前页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageCount\"&gt;总共多少页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"recordCount\"&gt;总记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;查询到的记录&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public List&lt;" + table.TableName + "&gt; GetListByPageLikeKey(" + table.TableName + " " + table.TableName.ToLower() + ",int PageSize, int NowPage, out int PageCount, out int recordCount){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            var objs = dbmanager.GetListByPageLikeKey(PageSize, NowPage, " + table.TableName.ToLower() + ", out PageCount, out recordCount);" + "<br/>");
            sb.AppendLine("            List&lt;" + table.TableName + "&gt; fields = new List&lt;" + table.TableName + "&gt;();" + "<br/>");
            sb.AppendLine("            foreach (" + table.TableName + " _field in objs)" + "<br/>");
            sb.AppendLine("            {" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("                fields.Add(_field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("            }" + "<br/>");
            sb.AppendLine("            return fields;" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 分页查询" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageSize\"&gt;每页记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"NowPage\"&gt;当前页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"PageCount\"&gt;总共多少页&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"recordCount\"&gt;总记录数&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;查询到的记录&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public List&lt;" + table.TableName + "&gt; GetListByPageAndKeys(" + table.TableName + " " + table.TableName.ToLower() + ",int PageSize, int NowPage, out int PageCount, out int recordCount){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            var objs = dbmanager.GetListByPageAndKeys(PageSize, NowPage, " + table.TableName.ToLower() + ", out PageCount, out recordCount);" + "<br/>");
            sb.AppendLine("            List&lt;" + table.TableName + "&gt; fields = new List&lt;" + table.TableName + "&gt;();" + "<br/>");
            sb.AppendLine("            foreach (" + table.TableName + " _field in objs)" + "<br/>");
            sb.AppendLine("            {" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("                fields.Add(_field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("            }" + "<br/>");
            sb.AppendLine("            return fields;" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 得到一个" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"id\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;对象&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public " + table.TableName + " GetModel(int id){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            " + table.TableName + " field = new " + table.TableName + "();" + "<br/>");
            sb.AppendLine("            field.Id = id;" + "<br/>");
            sb.AppendLine("            return dbmanager.GetModel(field) as " + table.TableName + ";" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 保存一个" + table.Description + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;编号&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public int Insert(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            return dbmanager.Insert(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 按关键字查询头几条" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"count\"&gt;数量&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;" + table.Description + "的列表&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public List&lt;" + table.TableName + "&gt; GetTopList(int count){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            " + table.TableName + " field = new " + table.TableName + "();" + "<br/>");
            sb.AppendLine("            var objs = dbmanager.GetTopList(count, field);" + "<br/>");
            sb.AppendLine("            List&lt;" + table.TableName + "&gt; fields = new List&lt;" + table.TableName + "&gt;();" + "<br/>");
            sb.AppendLine("            foreach (" + table.TableName + " _field in objs)" + "<br/>");
            sb.AppendLine("            {" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("                fields.Add(_field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("            }" + "<br/>");
            sb.AppendLine("            return fields;" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 判断" + table.Description + "是否唯一存在" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;是否存在&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public bool IsExist(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            return dbmanager.IsExist(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 判断" + table.Description + "是否存在" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;是否存在&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public bool IsJustExist(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            return dbmanager.IsJustExist(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 得到关键字等于。。。的所有" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;returns&gt;" + table.Description + "的List&lt;/returns&gt;" + "<br/>");
            sb.AppendLine("        public List&lt;" + table.TableName + "&gt; GetSomeObject(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            var objs = dbmanager.GetSomeObject(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("            List&lt;" + table.TableName + "&gt; fields = new List&lt;" + table.TableName + "&gt;();" + "<br/>");
            sb.AppendLine("            foreach (" + table.TableName + " _field in objs)" + "<br/>");
            sb.AppendLine("            {" + "<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("                fields.Add(_field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("            }" + "<br/>");
            sb.AppendLine("            return fields;" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 编辑一个" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"obj\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        public void Edit(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            dbmanager.Edit(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 删除一个" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        public void Delete(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            dbmanager.Delete(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 删除所有" + table.Description + "" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        public void DeleteAll(){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            " + table.TableName + " field = new " + table.TableName + "();" + "<br/>");
            sb.AppendLine("            dbmanager.DeleteAll(field);" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("        /// &lt;summary&gt;" + "<br/>");
            sb.AppendLine("        /// 按关键字删除" + "<br/>");
            sb.AppendLine("        /// &lt;/summary&gt;" + "<br/>");
            sb.AppendLine("        /// &lt;param name=\"" + table.TableName.ToLower() + "\"&gt;对象实体&lt;/param&gt;" + "<br/>");
            sb.AppendLine("        public void DeleteColumByKey_Value(" + table.TableName + " " + table.TableName.ToLower() + "){<br/>");
            sb.AppendLine("<div style=\"padding-left:40px;\">");
            sb.AppendLine("            dbmanager.DeleteColumByKey_Value(" + table.TableName.ToLower() + ");" + "<br/>");
            sb.AppendLine("</div>");
            sb.AppendLine("}<br/><br/>");

            sb.AppendLine("#endregion<br/><br/>");

            sb.AppendLine("#region 自定义接口实现<br/><br/><br/>");


            sb.AppendLine("#endregion<br/><br/>");

            sb.AppendLine("</div>");
            sb.AppendLine("}");

            sb.AppendLine("</div>");
            sb.AppendLine("}");

            return sb.ToString();
        }
    }
}